//
//  BuyGoodsViewController.m
//  FlowerRainGround
//
//  Created by lanou on 16/4/26.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import "BuyGoodsViewController.h"
#import "AddressViewController.h"
@interface BuyGoodsViewController ()

@end

@implementation BuyGoodsViewController


- (void) creatShower{
    if (self.typeID == 0) {
        [self.ImageView sd_setImageWithURL:[NSURL URLWithString:self.jingModel.fnAttachment1]];
        self.priceLabel.text = [NSString stringWithFormat:@"￥%ld", self.jingModel.goodsmodel.fnPrice];
        self.fnName.text = self.jingModel.fnName;
    }
    else{
        [self.ImageView sd_setImageWithURL:[NSURL URLWithString:self.mallmodel.fnAttachment1]];
        self.priceLabel.text = [NSString stringWithFormat:@"￥%ld", self.mallmodel.fnMarketPrice];
        self.fnName.text = self.mallmodel.fnName;
    }
}

- (IBAction)reduceCount:(id)sender {
    NSInteger count = [self.CountLabel.text integerValue];//商品总数
    NSInteger allPrice = [self.allPriceLabel.text integerValue];//总价
    if (count == 0) {
        count = 0;
    }else{
        count --;
    }
    self.CountLabel.text = [NSString stringWithFormat:@"%ld", count];
    self.countGooods.text = self.CountLabel.text;
    //商品总价
    if (self.typeID == 0) {
        allPrice = count * self.jingModel.goodsmodel.fnPrice;
    }else{
        allPrice = count * self.mallmodel.fnMarketPrice;
    }
    self.allPriceLabel.text = [NSString stringWithFormat:@"￥%ld", allPrice];
    self.sureAllPrice.text = [NSString stringWithFormat:@"%@",self.allPriceLabel.text];
    self.allPrice.text = [NSString stringWithFormat:@"%@",self.allPriceLabel.text];
}

- (IBAction)addCount:(id)sender {
    NSInteger count = [self.CountLabel.text integerValue];
    NSInteger allPrice = [self.allPriceLabel.text integerValue];//总价

    count ++;
    //商品个数
    self.CountLabel.text = [NSString stringWithFormat:@"%ld", count];
    self.countGooods.text = self.CountLabel.text;
    //商品总价
    if (self.typeID == 0) {
         allPrice = count * self.jingModel.goodsmodel.fnPrice;
    }else{
        allPrice = count * self.mallmodel.fnMarketPrice;
    }
    self.allPriceLabel.text = [NSString stringWithFormat:@"￥%ld", allPrice];
    self.sureAllPrice.text = [NSString stringWithFormat:@"%@",self.allPriceLabel.text];
    self.allPrice.text = [NSString stringWithFormat:@"%@",self.allPriceLabel.text];
}

- (IBAction)chooseAddress:(id)sender {
    AddressViewController *addreVC = [[AddressViewController alloc] init]
    ;
    [self.navigationController pushViewController:addreVC animated:YES];
    
}



- (void)viewDidLoad {
    [super viewDidLoad];
    [self creatShower];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
